<?php
/**
 *
 */

class HangSx extends ModelBase
{
    public function __construct()
    {
        parent::__construct(__CLASS__);
    }

    public function edit($params)
    {
        $this->run('UPDATE hangsx SET tenhsx=:tenhsx WHERE mahsx=:mahsx', $params);
        return 0;
    }

    public  function del($id)
    {
        $this->delete('mahsx=:id', array('id' => $id));
        return 0;
    }

    public function add($params)
    {
        $this->run('INSERT INTO hangsx VALUES(NULL, :tenhsx)', $params);
        $html = new Template(TEMPLATE_DIR . 'admin-hangsx-item.html');
        $html->setArray($params);
        $html['mahsx'] = $this->lastInsertId();
        return $html->render();

    }

    public function exists($id)
    {
        return $this->executeScalar('SELECT COUNT(*) FROM hangsx WHERE mahsx=:id',
            array('id' => $id));
    }
}
